﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.DataStruct;

namespace ConAppCore.Test
{
    internal class TestSpeedLimiter
    {
        public static void Test()
        {
            int id1 = 1, id2 = 2, id3 = 3;
            var speedLimiter = new SpeedLimiter<int>();
            speedLimiter.Add(id1, new SpeedLimitItem(500L));
            speedLimiter.Add(id2, new SpeedLimitItem(3));

            for (int i = 0; i < 20; i++)
            {
                var id1Ret = speedLimiter.Check(id1);
                Console.WriteLine($"{id1}:   {id1Ret.ToString()}");
                Thread.Sleep(100);
            }

            //var id1Ret1 = speedLimiter.Check(id1);
            //var id1Ret2 = speedLimiter.Check(id1);
            //Thread.Sleep(1000);
            //var id1Ret3 = speedLimiter.Check(id1);

            Console.WriteLine("--------------------------------");

            for (int i = 0; i < 20; i++)
            {
                var id2Ret = speedLimiter.Check(id2);
                Console.WriteLine($"{id2}:   {id2Ret.ToString()}");
            }

            Console.WriteLine("--------------------------------");

            for (int i = 0; i < 10; i++)
            {
                var id23Ret = speedLimiter.Check(id3);
                Console.WriteLine($"{id3}:   {id23Ret.ToString()}");
            }
        }
    }
}
